package com.lxd.sunso.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import com.lxd.sunso.common.utils.PageUtils;
import com.lxd.sunso.common.utils.R;
import com.lxd.sunso.product.vo.CurveVo;
import com.lxd.sunso.product.vo.RealDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lxd.sunso.product.entity.HistroydataEntity;
import com.lxd.sunso.product.service.HistroydataService;


import javax.servlet.http.HttpServletResponse;


/**
 * 
 *
 * @author lxd
 * @email sunlightcs@gmail.com
 * @date 2020-12-30 18:06:30
 */
@RestController
@RequestMapping("product/histroydata")
public class HistroydataController {
    @Autowired
    private HistroydataService histroydataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:histroydata:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = histroydataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:histroydata:info")
    public R info(@PathVariable("id") String id) {
        HistroydataEntity histroydata = histroydataService.getById(id);

        return R.ok().put("histroydata", histroydata);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:histroydata:save")
    public R save(@RequestBody HistroydataEntity histroydata) {
        histroydataService.saveHistorydata(histroydata);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:histroydata:update")
    public R update(@RequestBody HistroydataEntity histroydata) {
        histroydataService.updateById(histroydata);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:histroydata:delete")
    public R delete(@RequestBody String[] ids) {
        histroydataService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 获取完整历史记录信息
     */
    @RequestMapping("/listAll")
    //@RequiresPermissions("product:histroydata:delete")
    public R listAll(@RequestParam Map<String, Object> params) {
        RealDataVo data = histroydataService.listHistory(params);
        return R.ok().put("data", data);
    }


    /**
     * 历史数据的导出
     */
    @RequestMapping("/export")
    public void exportExcel(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        try {
            histroydataService.exportExcel(response, params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 曲线图
     *
     * @return
     */
    @RequestMapping("/curve")
    public R curve(@RequestParam Map<String, Object> params) throws ExecutionException, InterruptedException {
        List<CurveVo> list = histroydataService.curve(params);
        return R.ok().put("data", list);

    }
}
